home *** CD-ROM | disk | FTP | other *** search
/ 45 Great Windows Utilities 6 / 45 Great Windows Utilities Volume 6 MOJO-405 (Mojo Software).iso / ssblind / ssblind.c < prev    next >
C/C++ Source or Header  |  1992-07-07  |  4KB  |  137 lines

  1. /*----------------------------------------
  2.    SSBLIND.C -- Pull Blinds on Windows
  3.                 (c) Paul J. Gyugyi, 1992
  4.    Based on:    Mixup Screen Saver
  5.                 (c) Charles Petzold, 1992
  6.   ----------------------------------------*/
  7.  
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include <scrnsave.h>
  11. #include <stdlib.h>
  12.  
  13. #define ID_TIMER    1
  14. #define UINT unsigned int
  15.  
  16. char szAppName [] = "ScreenSaver.Blind" ;
  17. char szProfKey [] = "Sound" ;
  18. int  noise = MB_ICONSTOP;
  19.  
  20. LONG FAR PASCAL ScreenSaverProc (HWND hwnd,   UINT message,
  21.                                  WORD wParam, LONG lParam)
  22.      {
  23.      static int      iIndex ;
  24.      static short    cxClient, cyClient ;
  25.      static HDC      hdc ;
  26.      static HWND     hwnd2;
  27.      RECT             rect;
  28.      static HRGN     hrgn;
  29.      int             rheight;
  30.      HBRUSH          dabrush;
  31.      static int      isound;
  32.  
  33.      switch (message)
  34.           {
  35.           case WM_CREATE:
  36.                isound = GetProfileInt(szAppName,szProfKey,0);
  37.                cxClient = GetSystemMetrics (SM_CXSCREEN) ;
  38.                cyClient = GetSystemMetrics (SM_CYSCREEN) ;
  39.                SetTimer (hwnd, ID_TIMER, 1000/16, NULL) ;
  40.                hwnd2=GetWindow(hwnd,GW_HWNDFIRST);
  41.                hrgn=CreateRectRgn(0,0,cxClient,cyClient);
  42.                hdc = GetDC (hwnd) ;
  43.                SelectObject(hdc,
  44.                  CreatePen(PS_SOLID,2,RGB(0,255,255)));
  45.                SelectObject(hdc,
  46.                  CreateHatchBrush(HS_HORIZONTAL,RGB(192,192,192)));
  47.                SetBkMode(hdc,OPAQUE);
  48.                SetBkColor(hdc,RGB(128,128,128));
  49.                SelectClipRgn(hdc,hrgn);
  50.                break ;
  51.  
  52.           case WM_ERASEBKGND:
  53.                return 1 ;
  54.  
  55.           case WM_TIMER:
  56.                if (hwnd2 != NULL) {
  57.                  if ((hwnd2 != hwnd)    &&
  58.                      (IsWindow(hwnd2))  &&
  59.                      (IsWindowVisible(hwnd2))) {
  60.                    GetWindowRect(hwnd2,&rect);
  61.                    dabrush=SelectObject(hdc,
  62.                      GetStockObject(BLACK_BRUSH));
  63.                    UnrealizeObject(dabrush);
  64.                    SetBrushOrg(hdc,rect.left,rect.top);
  65.                    SelectObject(hdc,dabrush);
  66.                    rheight=rect.bottom - rect.top;
  67.                    Rectangle(hdc,rect.left,rect.top+rheight/4,
  68.                      rect.right,rect.top);
  69.                    Rectangle(hdc,rect.left,rect.top,
  70.                      rect.right,rect.top + rheight/2);
  71.                    Rectangle(hdc,rect.left,rect.top,
  72.                      rect.right,rect.top+rheight*3/4);
  73.                    if (isound) {
  74.                      MessageBeep(noise);
  75.                    }
  76.                    Rectangle(hdc,rect.left,rect.top,
  77.                      rect.right,rect.bottom);
  78.                    ExcludeClipRect(hdc,
  79.                      rect.left,rect.top,rect.right,rect.bottom);
  80.                  };
  81.                };
  82.                  hwnd2 = GetWindow(hwnd2,GW_HWNDNEXT);
  83.                return 0 ;
  84.  
  85.           case WM_DESTROY:
  86.                KillTimer (hwnd, ID_TIMER) ;
  87.                DeleteObject(SelectObject(hdc,
  88.                  GetStockObject(BLACK_PEN)));
  89.                DeleteObject(SelectObject(hdc,
  90.                  GetStockObject(BLACK_BRUSH)));
  91.                ReleaseDC (hwnd, hdc) ;
  92.                DeleteObject(hrgn);
  93.                break ;
  94.           }
  95.  
  96.      return DefScreenSaverProc (hwnd, message, wParam, lParam) ;
  97.      }
  98.  
  99. BOOL FAR PASCAL ScreenSaverConfigureDialog (HWND hDlg,   UINT message,
  100.                                             WORD wParam, LONG lParam)
  101.      {
  102.      static int isound;
  103.      char szSound[8];
  104.  
  105.      switch(message) {
  106.        case WM_INITDIALOG:
  107.          isound = GetProfileInt(szAppName,szProfKey,0);
  108.          CheckDlgButton(hDlg,101,isound);
  109.          return TRUE;
  110.        case WM_COMMAND:
  111.          switch(wParam) {
  112.            case 101:
  113.              if (IsDlgButtonChecked(hDlg,101)) {
  114.                isound=1;
  115.              }else{
  116.                isound=0;
  117.              }
  118.              return TRUE;
  119.            case IDOK:
  120.              itoa(isound,szSound,10);
  121.              WriteProfileString(szAppName,szProfKey,szSound);
  122.              EndDialog(hDlg, TRUE);
  123.              return TRUE;
  124.            case IDCANCEL:
  125.              EndDialog(hDlg,FALSE);
  126.              return TRUE;
  127.          }
  128.          break;
  129.      }
  130.      return FALSE ;
  131.      }
  132.  
  133. BOOL RegisterDialogClasses (HANDLE hInstanc)
  134.      {
  135.      return TRUE ;
  136.      }
  137.